﻿namespace Arms.Application.Ninjection
{
    using Arms.Application.Modules.Security;
    using Arms.Domain;
    using Arms.Framework.Adapters;
    using Arms.Framework.Security;
    using Arms.Framework.Security.Encryptors;
    using Arms.Persistence;
    using Ninject.Activation;
    using Ninject.Modules;
    using Ninject.Parameters;
    using System;
    using System.Linq;

    public class CommonModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IDbContext>().To<ArmsContext>();
            Bind<IUnitOfWork>().To<ArmsUnitOfWork>();
            Bind<IUser>().To<ArmsUser>();

            IRequest request = new Request(typeof(AutoMapperTypeAdapterFactory), null, new Parameter[0], null, true, true);
            var typeAdapterFactory = base.Kernel.Resolve(request).SingleOrDefault() as AutoMapperTypeAdapterFactory;
            TypeAdapterFactory.SetCurrent(typeAdapterFactory);

            // LoggerFactory
            //LoggerFactory.SetCurrent(new DebugLoggerFactory());

            // EncryptorFactory
            EncryptorFactory.SetCurrent(new SHA256EncryptorFactory());
        }
    }
}
